package net.wanho.service.impl;

import lombok.RequiredArgsConstructor;
import net.wanho.entity.User;
import net.wanho.mapper.UserMapper;
import net.wanho.service.UserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;

/**
 * Author：汤小洋
 * Date：2023-10-12 9:24
 * Description：<描述>
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    @Override
    public void register(User user) {
        // 设置盐值
        user.setSalt(user.getUsername());
        // 对密码进行加密
        Md5Hash md5Hash = new Md5Hash(user.getPassword(), user.getSalt(), 1024);
        user.setPassword(md5Hash.toHex());

        userMapper.insert(user);
    }

    @Override
    public User findByUsername(String username) {
        User user = userMapper.selectByUsername(username);
        return user;
    }
}
